<template>
  <div class="container">
    <!-- 布局容器 -->
    <el-container>
      <!-- 头部区域 -->
      <el-header>
        <div class="header">
          <!-- 控制下方菜单栏 -->
          <div class="header-left">
            <el-switch
              v-model="toggleNav"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="toggleNavcss()"
            >
            </el-switch>
            <!-- 刷新按钮 -->
            <div
              class="refresh"
              @click="openFullScreen1"
              v-loading.fullscreen.lock="fullscreenLoading"
            >
              刷新
            </div>
          </div>
          <!-- 搜索按钮 -->
          <div class="header-right">
            <!-- 搜索按钮 -->
            <el-button icon="el-icon-search" circle @click="searchTc()">
              <slot>
                <div class="searchTc" v-if="showserchTc">666</div>
              </slot>
            </el-button>
            <!-- //消息按钮弹窗 -->
            <div class="news" @click="newsTc()">
              3
              <div class="newstc" v-if="shownewsTc">555</div>
            </div>
            <!-- 头像按钮弹窗 -->
            <div class="user" @click="userTc()">
              头像
              <div class="usertc" v-if="showuserTc">
                <el-button type="info" @click="out()" size="small"
                  >退出</el-button
                >
              </div>
            </div>
          </div>
        </div>
      </el-header>
      <el-container>
        <!-- 侧边栏区域 -->
        <el-aside width="25%" v-if="showaside">
          <div class="nav">
            <el-menu
              unique-opened
              ref="menu"
              active-text-color="#409EFF"
              router
              @select="handleroute"
              :default-active="activePath"
            >
              <el-menu-item index="index">
                <i class="el-icon-s-home"></i>
                <span slot="title">首页</span>
              </el-menu-item>
              <el-submenu index="2">
                <template slot="title">
                  <i class="el-icon-plus"></i>
                  <span>任务</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="training-task">新建训练任务</el-menu-item>
                  <el-menu-item index="test-task">新建测试任务</el-menu-item>
                  <el-menu-item index="report-task">新建报表任务</el-menu-item>
                  <el-menu-item index="task-group">新建任务组</el-menu-item>
                  <el-menu-item index="training-record"
                    >训练任务记录</el-menu-item
                  >
                  <el-menu-item index="test-record">测试任务记录</el-menu-item>
                  <el-menu-item index="report-record"
                    >报表任务记录</el-menu-item
                  >
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-plus"></i>
                  <span>数据集</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="data-upload">上传数据库</el-menu-item>
                  <el-menu-item index="data-control">数据库管理</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
              <el-submenu index="4">
                <template slot="title">
                  <i class="el-icon-plus"></i>
                  <span>模型</span>
                </template>
                <el-menu-item-group>
                  <template slot="title"></template>
                  <el-menu-item index="model-upload">上传模型</el-menu-item>
                  <el-menu-item index="model-control">模型管理</el-menu-item>
                </el-menu-item-group>
              </el-submenu>
            </el-menu>
          </div>
        </el-aside>
        <!-- 页面主体区域 -->
        <el-main><router-view></router-view></el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import { baseUrls } from "@/main.js";
export default {
  data() {
    return {
      // 菜单栏控制
      showaside: true,
      toggleNav: true,
      // 标题栏弹窗
      togeleserchTc: false,
      showserchTc: false,
      shownewsTc: false,
      showuserTc: false,
      // 刷新界面
      fullscreenLoading: false,
      activePath: "",
      token: {
        token: "",
      },
    };
  },
  methods: {
    //导航栏
    handleroute() {
      sessionStorage.setItem("navsession", this.$refs.menu.openedMenus[0]);
    },
    // 搜索按钮弹窗
    searchTc() {
      this.showserchTc = !this.showserchTc;
      this.shownewsTc = false;
      this.showuserTc = false;
    },
    // 消息按钮弹窗
    newsTc() {
      this.shownewsTc = !this.shownewsTc;
      this.showuserTc = false;
      this.showserchTc = false;
    },
    // 用户按钮弹窗
    userTc() {
      this.showuserTc = !this.showuserTc;
      this.showserchTc = false;
      this.shownewsTc = false;
      //获取用户信息
      let res = this.$http
        .get(`${baseUrls.base1}/center/validate/?token=${this.token.token}`)
        .then((res) => {
          console.log(res);
        });
    },
    toggleNavcss() {
      this.showaside = !this.showaside;
    },
    // 刷新界面按钮
    openFullScreen1() {
      this.fullscreenLoading = true;
      setTimeout(() => {
        this.fullscreenLoading = false;
        location.reload();
      }, 2000);
    },
    //退出功能
    async out() {
      const { data: res } = await this.$http.get(
        `${baseUrls.base1}/center/logout/?token=${this.token.token}`
      );
      window.sessionStorage.clear("token");
      this.$message.success("退出成功");
      this.$router.push("/login");
    },
    saveNavstate(activePath) {
      // 保存链接的激活状态
      window.sessionStorage.setItem("activePath", activePath);
      this.activePath = activePath;
    },
  },
  //生命周期函数
  created() {
    this.token.token = window.sessionStorage.getItem("token");
    this.activePath = window.sessionStorage.getItem("activePath");
    // console.log(this.token.token);
  },
  mounted() {
    if (sessionStorage.getItem("navsession")) {
      this.$refs.menu.open(sessionStorage.getItem("navsession"));
    }
  },
};
</script>
<style  scoped>
/* 头部区域样式 */
.el-header {
  padding: 0 10px;
  margin-bottom: 10px;
  margin-top: 10px;
}
/* 菜单栏样式 */
.el-aside {
  background-color: #f3f4f7;
  padding: 5px;
  height: 100%;
}
.el-main {
  background-color: #fff;
  border-radius: 10px;
  margin-top: 5px;
  margin-right: 10px;
  height: 92%;
}
.nav {
  width: 95%;
  height: 98%;
  margin: 0px auto;
  border-radius: 10px;
  overflow: hidden;
}
.el-menu {
  height: 95%;
  margin-bottom: 100px;
}
@import url("//unpkg.com/element-ui@2.15.6/lib/theme-chalk/index.css");
/* 头部样式 */
.header {
  background-color: #fff;
  height: 100%;
  width: 100%;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
}
.header-right {
  display: flex;
  justify-content: space-between;
  width: 15%;
  margin-top: 10px;
  margin-right: 20px;
}
.header-left {
  display: flex;
  justify-content: space-between;
  width: 15%;
  margin-top: 10px;
  margin-right: 20px;
}
.el-switch {
  position: absolute;
  margin: 10px 10px;
}
.el-button {
  height: 40px;
  width: 40px;
}
.news,
.user,
.refresh {
  width: 40px;
  height: 40px;
  background-color: #fad7dd;
  border-radius: 50%;
  text-align: center;
  color: #ee6e83;
  line-height: 40px;
  cursor: pointer;
  position: relative;
  /* overflow: hidden; */
}
.refresh {
  position: absolute;
  left: 8%;
}
.el-icon-search {
  position: relative;
}
.searchTc,
.newstc,
.usertc {
  position: relative;
  width: 340px;
  height: 200px;
  background-color: white;
  right: 300px;
  top: 13px;
  border-radius: 15px;
  box-shadow: 0 0 1.25rem rgb(31 45 61 / 5%);
  margin: 10px 0;
  display: block;
}
.newstc {
  top: 0;
}
.usertc {
  top: 0;
}
</style>
